/** @file
 *  Example code for controlling Newport ESP301 motion controller.
 *  This example open the device on COM0.
 *  If the opening is successful, it moves to position zero, and
 *  then move by 0.5 micron for 100 times.
 */

#include <iostream>
#include "esp301-control.h"

int
main ()
{


  try
  {

    esp301_control Motion_controller;

    Motion_controller.connect ();

    Motion_controller.moveTo (0);

    double dx = 0.0005;
    for (int i = 0; i < 100; i++)
      {
	Motion_controller.moveBy (dx);

	float displacement;
	displacement = Motion_controller.getPosition ();

	std::
	  cout << "Current position:" << displacement <<
	  "\tTheoretical position: " << Motion_controller.
	  theoretical_displacement << std::endl;
      }


  }
  catch (char const *str_err)
  {
    std::cerr << "[ERROR] " << str_err << std::endl;
    return 1;
  }

  return 0;
}
